package com.defysoft.waukids.notice;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.defysoft.waukids.BaseActivity_UpPhoto;
import com.defysoft.waukids.Custom_Data_Type.NoticeDetailLoad_Two;
import com.defysoft.waukids.Data_Sharedpreferences;
import com.defysoft.waukids.Data_Type.WK_NOTICE_PHOTO;
import com.defysoft.waukids.JsonParser;
import com.defysoft.waukids.PublicConstant;
import com.defysoft.waukids.PublicSharedpreferences;
import com.defysoft.waukids.R;
import com.defysoft.waukids.Sqlite_Connect;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

public class NoticeDetailActivity extends BaseActivity_UpPhoto implements
		OnClickListener {
	int noticeCode;
	int photo_count = 0;
	NoticeDetailLoad_Two NoticeDetailLoad_Two;
	ArrayList<WK_NOTICE_PHOTO> photoList;
	ImageView imageView[] = new ImageView[10];
	LinearLayout linearLayout[] = new LinearLayout[10];
	TextView textView[] = new TextView[4];
	Intent intent;
	Toolbar toolbar;
	// 스피너
	Spinner spinner;
	String[] celebrities = { "수정", "삭제", "미확인부모" };
	ScrollView mScroll;
	Sqlite_Connect sc;
	SharedPreferences.Editor editor;
	PublicSharedpreferences psf;
	Data_Sharedpreferences.SF_Member member;
	Data_Sharedpreferences.SF_Student student;
	// 이미지업로드
	DisplayImageOptions options;
	ImageLoader imageLoader;

	// 1분전,1일전,
	String now_date;
	long now = System.currentTimeMillis();
	Date date = new Date(now);
	SimpleDateFormat CurYearFormat ;
	SimpleDateFormat CurMonthFormat;
	SimpleDateFormat CurDayFormat ;
	SimpleDateFormat CurHourFormat ;
	SimpleDateFormat CurMinuteFormat;
	SimpleDateFormat CurSecondFormat;
	// 하단
	int stamp_a_count, stamp_b_count, stamp_c_count = 0;
	Button button[] = new Button[1];
	// 미확인 부모 리스트
	Handler mHandler;
	public Sqlite_Connect sqlite_Connect;
	int mode = 0;
	int photo_select=0;
	private final int FIRST_THREAD = 0;
	private final int STAMP_A_THREAD = 1;
	private final int STAMP_B_THREAD = 2;
	private final int STAMP_C_THREAD = 3;
	private final int DELETE_THREAD = 4;
	private final int SUCCESS_DELETE = 5;
	private final int FAIL_DELETE = 6;
	private final int SUCCESS_STAMP = 7;
	private final int FAIL_STAMP = 8;
	private final int SUCCESS_FIRST = 9;
	private final int FAIL_FIRST = 10;
	private final int NOREAD_THREAD = 11;
	private final int SUCCESS_NOREAD = 12;
	private final int FAIL_NOREAD = 13;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case START_NOTICE_DETAIL: // 9010
			if (resultCode == REFRESH_CODE) { // 5555
				setResult(REFRESH_CODE);
				setStartData();
				startNetwork(FIRST_THREAD);
			}
			break;

		default:
			break;
		}
	}

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
			noticeCode = Integer.parseInt(getIntent().getStringExtra(
					"PK_Not_Code"));
		setContentView(R.layout.noticedetail_activity);
		setStartData();
		setImgSetting();
		startNetwork(FIRST_THREAD);
		setStartToolbar();
		
		registerReceiver(mToastMessageReceiver, new IntentFilter(
				"com.defysoft.waukids.TOAST_MESSAGE"));
	}

	@Override
	public void setStartData() {
		super.setStartData();
		sqlite_Connect = new Sqlite_Connect(this);
		CurYearFormat = new SimpleDateFormat("yyyy"); 
		CurMonthFormat = new SimpleDateFormat("MM");  
		CurDayFormat = new SimpleDateFormat("dd");    
		CurHourFormat = new SimpleDateFormat("HH");   
		CurMinuteFormat = new SimpleDateFormat("mm"); 
		CurSecondFormat = new SimpleDateFormat("ss"); 
		photoList = new ArrayList<WK_NOTICE_PHOTO>();
		psf = new PublicSharedpreferences(this);
		psf.setMembersp();
		member = psf.getMembersp();
		if (member.Rank.equals("3")) {
			psf.setStudentsp();
			student = psf.getStudentsp();
		}
		// 미확인 부모 리스트
		mHandler = new Handler();
		/** 공지 제목 */
		textView[0] = (TextView) findViewById(R.id.NOTICE_DETAIL_NAME);
		/** 공지 내용 */
		textView[1] = (TextView) findViewById(R.id.NOTICE_DETAIL_CONTENTS);
		/** 공지 지난 시간 */
		textView[2] = (TextView) findViewById(R.id.NOTICE_DETAIL_ELAPSED_TIME);
		
		/** 공지 작성자 등급. */
		textView[3] = (TextView) findViewById(R.id.NOTICE_DETAIL_RANK);
		mScroll = (ScrollView) findViewById(R.id.NOTICE_DETAIL_SCROLLVIEW);
		/** 공지 사진 */
		imageView[0] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_1);
		imageView[1] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_2);
		imageView[2] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_3);
		imageView[3] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_4);
		imageView[4] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_5);
		imageView[5] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_6);
		imageView[6] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_7);
		imageView[7] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_8);
		imageView[8] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_9);
		imageView[9] = (ImageView) findViewById(R.id.NOTICE_DETAIL_IMG_10);
		// 사진 리니어레이아웃.
		linearLayout[0] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_1_LL);
		linearLayout[1] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_2_LL);
		linearLayout[2] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_3_LL);
		linearLayout[3] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_4_LL);
		linearLayout[4] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_5_LL);
		linearLayout[5] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_6_LL);
		linearLayout[6] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_7_LL);
		linearLayout[7] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_8_LL);
		linearLayout[8] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_9_LL);
		linearLayout[9] = (LinearLayout) findViewById(R.id.NOTICE_DETAIL_IMG_10_LL);
		// 하단 스탬프.
/*		button[0] = (Button) findViewById(R.id.NOTICE_DETAIL_BUTTON_UNIDENTIFIED_PARENTS);
		button[1] = (Button) findViewById(R.id.NOTICE_DETAIL_BUTTON_STAMP_A);
		button[2] = (Button) findViewById(R.id.NOTICE_DETAIL_BUTTON_STAMP_B);
		button[3] = (Button) findViewById(R.id.NOTICE_DETAIL_BUTTON_STAMP_C);

		button[0].setOnClickListener(this);
		if (member.Rank.equals("3")) {
			button[1].setOnClickListener(this);
			button[2].setOnClickListener(this);
			button[3].setOnClickListener(this);
		}*/

		// 사진 클릭시
		for (int i = 0; i < 10; i++) {
			final int ii = i;
			imageView[i].setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					intent = new Intent(NoticeDetailActivity.this,
							NoticeDetailPhoto.class).putExtra(
							"photo",
							PublicConstant.HTTP_URL_NOTICEPHOTO
									+ photoList.get(ii).Not_Pho_IMG).putExtra(
							"photoname", photoList.get(ii).Not_Pho_IMG);
					startActivity(intent);
				}
			});
		}

		toolbar = (Toolbar) findViewById(R.id.NOTICE_DETAIL_TOOLBAR);
		spinner = (Spinner) findViewById(R.id.NOTICE_DETAIL_SPI);
		sc = new Sqlite_Connect(this);
		
		sc.delete_New_Notice(noticeCode);
	}

	private void setStartToolbar() {
		toolbar.setNavigationOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		spinner.setAdapter(new ArrayAdapter<String>(this, 0) {
			@Override
			public int getCount() {
				return celebrities.length;
			}

			@Override
			public View getDropDownView(int position, View convertView,
					ViewGroup parent) {
				final int pos = position;
				final View conView = convertView;
				if (convertView == null) {
					convertView = getLayoutInflater().inflate(
							R.layout.overflowitem_row, null);
				}
				
					((TextView) convertView.findViewById(R.id.OVERFLOWITEM_TV))
						.setText(celebrities[position]);
					
					
					/*switch (pos) {
					case 0:	//수정
						if (mode == 0) {
							convertView.setBackgroundColor(0xff37b34a);
						}						
						break;
					case 1: //삭제
						if (mode == 1) {
							convertView.setBackgroundColor(0xff37b34a);
						}					
						break;
					case 2: //미확인부모.
						if (mode == 2) {
							convertView.setBackgroundColor(0xff37b34a);
						}						
						break;

					}*/
					convertView.setOnTouchListener(new OnTouchListener() {
						@Override
						public boolean onTouch(View v, MotionEvent event) {
							switch (pos) {
							case 0: // 수정하기
								if (event.equals(MotionEvent.ACTION_DOWN)) {
									conView.setBackgroundColor(0xff37b34a);
								}
								Intent i = new Intent(NoticeDetailActivity.this,
										Notice_Main_Edit.class).putExtra(
										"PK_Not_Code",
										Integer.toString(NoticeDetailLoad_Two.PK_Not_Code));
								startActivityForResult(i, START_NOTICE_DETAIL);
								break;
							case 1: // 삭제하기
								alertDialog("삭제 하시겠습니까?", DELETE_THREAD);
								break;
							case 2:
								startNetwork(NOREAD_THREAD);
								break;
							}
							return false;
						}
					});
/*				convertView.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						
						switch (pos) {
						case 0: // 수정하기
							
							Intent i = new Intent(NoticeDetailActivity.this,
									Notice_Main_Edit.class).putExtra(
									"PK_Not_Code",
									Integer.toString(NoticeDetailLoad_Two.PK_Not_Code));
							startActivityForResult(i, START_NOTICE_DETAIL);
							
							break;
						case 1: // 삭제하기

							alertDialog("삭제 하시겠습니까?", DELETE_THREAD);
							break;
						case 2:
							startNetwork(NOREAD_THREAD);
							break;

						}
					}
				});*/
				
				return convertView;
			}
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				final int pos = position;
				if (convertView == null) {
					convertView = getLayoutInflater().inflate(
							R.layout.overflowitem_row, null);
				}
				((TextView) convertView.findViewById(R.id.OVERFLOWITEM_TV))
						.setBackgroundColor(0x00ffffff);
				return convertView;
			}
		});

/*		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:	//수정

						Intent i = new Intent(NoticeDetailActivity.this,
								Notice_Main_Edit.class).putExtra(
								"PK_Not_Code",
								Integer.toString(NoticeDetailLoad_Two.PK_Not_Code));
						startActivityForResult(i, START_NOTICE_DETAIL);
								
					break;
				case 1:	//삭제

						alertDialog("삭제 하시겠습니까?", DELETE_THREAD);
							
					break;
				case 2:	//미확인부모

						startNetwork(NOREAD_THREAD);
							
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
		});*/
		
		
	}

	@Override
	public void startThread(int choice) {
		super.startThread(choice);
		final int cho = choice;
		firstThread = new Thread(new Runnable() {
			@Override
			public void run() {
				switch (cho) {
				case FIRST_THREAD:
					noticeDetailThread();
					break;
				case STAMP_A_THREAD:
					stampThread("Not_Stamp_A", stamp_a_count + 1);
					break;
				case STAMP_B_THREAD:
					stampThread("Not_Stamp_B", stamp_b_count + 1);
					break;
				case STAMP_C_THREAD:
					stampThread("Not_Stamp_C", stamp_c_count + 1);
					break;
				case DELETE_THREAD:
					deleteThread();
					break;
				case NOREAD_THREAD:
					noReadThread();
					break;

				}
			}
		});
		firstThread.start();
	}

	protected void deleteThread() {
		String msg = "";
		try {
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_NOTICE_DETAIL_DELETE + "&PK_Not_Code="
							+ noticeCode));
			if (jsonObject.getBoolean("success")) {
				onNetworkCallback(SUCCESS_DELETE,
						jsonObject.getString("payload"));// 다시 받아오지 말고, 눌리면 바로
															// 숫자1올라가고,
			} else {
				onNetworkCallback(FAIL_DELETE, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(CATCH_EXCEPTION, e.toString()+" where deleteThread()");
		}
	}

	protected void stampThread(String string, int count) {
		final String stamp = string;
		final int stampCount = count;
		String msg = "";
		try {
			sc.insert_NoticeStamp(noticeCode, Integer.parseInt(student.Code));
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_NOTICE_DETAIL_STAMP + "&PK_Not_Code="
							+ noticeCode + "&Not_Stamp_=" + stamp
							+ "&stampCount=" + stampCount));
			if (jsonObject.getBoolean("success")) {
				NoticeDetailLoad_Two = JsonParser.NoticeDetailLoad_Two(jsonObject
						.getString("payload"));
				onNetworkCallback(SUCCESS_STAMP,
						jsonObject.getString("payload"));
			} else {
				onNetworkCallback(FAIL_STAMP, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(CATCH_EXCEPTION, e.toString()+" where stampThread(String string, int count)");
		}
	}

	protected void noticeDetailThread() {
		String msg = "";
		try {
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_NOTICE_DETAIL_LOAD 
					+ "&PK_Not_Code=" + noticeCode
					+ "&email=" + member.Email
					
					));
			if (jsonObject.getBoolean("success")) {
				NoticeDetailLoad_Two = JsonParser.NoticeDetailLoad_Two(jsonObject
						.getString("payload"));
				this.photoList = JsonParser.noticePhotoList(jsonObject
						.getString("photo"));
				this.photo_count = jsonObject.getInt("count");
				this.now_date = jsonObject.getString("nowdate"); // 현재시간

				onNetworkCallback(SUCCESS_FIRST, "");
			} else {
				onNetworkCallback(FAIL_FIRST, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(CATCH_EXCEPTION, e.toString()+" where noticeDetailThread()");
		}
	}

	@Override
	protected void handlingMessage(Message _message) {
		super.handlingMessage(_message);
		switch (_message.what) {
		case SUCCESS_FIRST:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			textView[0].setText(NoticeDetailLoad_Two.Not_Name);
			textView[1].setText(NoticeDetailLoad_Two.Not_Sub);
			textView[3].setText(NoticeDetailLoad_Two.Not_Writer);
			/*//선생님인지 원장님인지.
			if (NoticeDetailLoad_Two.Cla_Name.equals("") ||NoticeDetailLoad_Two.Cla_Name.equals("null")) {
				textView[3].setText(NoticeDetailLoad_Two.Not_Writer);
			} else {
				textView[3].setText(NoticeDetailLoad_Two.Cla_Name+" 선생님");
			}*/
			
			
		
			/*stamp_a_count = NoticeDetailLoad_Two.Not_Stamp_A;
			stamp_b_count = NoticeDetailLoad_Two.Not_Stamp_B;
			stamp_c_count = NoticeDetailLoad_Two.Not_Stamp_C;*/
			/*button[1].setText(Integer.toString(stamp_a_count));
			button[2].setText(Integer.toString(stamp_b_count));
			button[3].setText(Integer.toString(stamp_c_count));*/
			// 작성자만 스피너 보이게.
			if (member.Email.equals(NoticeDetailLoad_Two.FK_Mem_Not_Email)) {
				spinner.setVisibility(View.VISIBLE); // 보이게.
			}
			timeCalculation(); // 경과시간계산기.
			if (photo_count > 10) {
				photo_count = 10;
			}
			if (photo_count > 0) {
				for (int i = 0; i < photo_count; i++) {
					/* imageView[i].setVisibility(View.VISIBLE); */
					linearLayout[i].setVisibility(View.VISIBLE);
					imageLoader.displayImage(
							PublicConstant.HTTP_URL_NOTICEPHOTO
									+ photoList.get(i).Not_Pho_IMG,
							imageView[i], options, null);
				}
			}

			break;
		case FAIL_FIRST:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(this, (String) _message.obj, Toast.LENGTH_LONG)
					.show();
			setResult(REFRESH_CODE);
			finish();
			break;

		case SUCCESS_STAMP:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			stamp_a_count = NoticeDetailLoad_Two.Not_Stamp_A;
			stamp_b_count = NoticeDetailLoad_Two.Not_Stamp_B;
			stamp_c_count = NoticeDetailLoad_Two.Not_Stamp_C;
			button[1].setText(Integer.toString(stamp_a_count));
			button[2].setText(Integer.toString(stamp_b_count));
			button[3].setText(Integer.toString(stamp_c_count));
			break;

		case FAIL_STAMP:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(this, (String) _message.obj, Toast.LENGTH_SHORT)
					.show();
			break;
		case SUCCESS_DELETE:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(this, (String) _message.obj, Toast.LENGTH_SHORT)
					.show();
			setResult(REFRESH_CODE);
			finish();
			break;

		case FAIL_DELETE:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(this, (String) _message.obj, Toast.LENGTH_SHORT)
					.show();
			break;

		case SUCCESS_NOREAD: // 미확인부모리스트
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			String testmsg = (String) _message.obj;
			String[] testlist = testmsg.split(",");
			testmsg = "";
			for (int i = 0; i < testlist.length; i++) {
				testmsg += testlist[i] + "\n";
			}
			showPopup("미확인 부모님", testmsg, 0);
			break;

		case FAIL_NOREAD: // 미확인부모리스트
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(this, (String) _message.obj, Toast.LENGTH_SHORT)
					.show();
			break;

		case CATCH_EXCEPTION:
			endDIal();
			if (firstThread != null) {
				firstThread.interrupt();
			}
			sqlite_Connect.insert_Err_Log((String)_message.obj,android.os.Build.VERSION.SDK_INT,"NoticeDetailActivity", member.Email);
			break;

		}
	}

	public void setImgSetting() {
		// 이미지 세팅.
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				this).threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.writeDebugLogs() // Remove for release app
				.build();
		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(config);
		imageLoader = ImageLoader.getInstance();
		options = new DisplayImageOptions.Builder().cacheInMemory(true)
		/* .imageScaleType(ImageScaleType.EXACTLY) */
		.cacheOnDisc(true).considerExifParams(true).build();
	}

	/** 경과일자시간계산기 */
	protected void timeCalculation() {
		// 시간 계산기. split
		String notice_date = NoticeDetailLoad_Two.Not_Date;

		// 1.공지사항 시간.
		String not_date = notice_date.split(" ")[0];
		String not_time = notice_date.split(" ")[1];
		// 일월년 분할.
		int not_year = Integer.parseInt(not_date.split("-")[0]);
		int not_month = Integer.parseInt(not_date.split("-")[1]);
		int not_day = Integer.parseInt(not_date.split("-")[2]);
		// 시분초 분할.
		int not_hour = Integer.parseInt(not_time.split(":")[0]);
		int not_minute = Integer.parseInt(not_time.split(":")[1]);
		int not_second = Integer.parseInt(not_time.split(":")[2]);

		// 2. 현재날짜시간
		int now_year = Integer.parseInt(CurYearFormat.format(date));
		int now_month = Integer.parseInt(CurMonthFormat.format(date));
		int now_day = Integer.parseInt(CurDayFormat.format(date));
		int now_hour = Integer.parseInt(CurHourFormat.format(date));
		int now_minute = Integer.parseInt(CurMinuteFormat.format(date));
		int now_second = Integer.parseInt(CurSecondFormat.format(date));

		// 3. 계산기 시작.
		if (not_year < now_year) {
			textView[2].setText(not_date);
		} else if (not_month < now_month) {
			int a = (now_month - not_month);
			textView[2].setText(a + " 개월 전");
		} else if (not_day < now_day) {
			int aa = (now_day - not_day);
			textView[2].setText(aa + " 일 전");
		} else if (not_hour < now_hour) {
			int aaa = (now_hour - not_hour);
			textView[2].setText(aaa + " 시간 전");
		} else if (not_minute < now_minute) {
			int aaaa = (now_minute - not_minute);
			textView[2].setText(aaaa + " 분 전");
		} else if (not_minute == now_minute) {
			textView[2].setText("방금 전");

		}
		// 계산기 끝.
		/** 하단 미확인부모, 스탬프3개 */

	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
/*		case R.id.NOTICE_DETAIL_BUTTON_UNIDENTIFIED_PARENTS: // 미확인부모리스트
			startNetwork(NOREAD_THREAD);
			break;*/
/*		case R.id.NOTICE_DETAIL_BUTTON_STAMP_A: // 스탬프A
			if (sc.stamp_Notice(noticeCode, Integer.parseInt(student.Code))) {
				alertDialog("스탬프A?", STAMP_A_THREAD);
			} else {
				Toast.makeText(this, "부모님만 스탬프 선택이 가능합니다.", Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.NOTICE_DETAIL_BUTTON_STAMP_B: // 스탬프B
			if (sc.stamp_Notice(noticeCode, Integer.parseInt(student.Code))) {
				alertDialog("스탬프B?", STAMP_B_THREAD);
			} else {
				Toast.makeText(this, "부모님만 스탬프 선택이 가능합니다.", Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.NOTICE_DETAIL_BUTTON_STAMP_C: // 스탬프C
			if (sc.stamp_Notice(noticeCode, Integer.parseInt(student.Code))) {
				alertDialog("스탬프C?", STAMP_C_THREAD);
			} else {
				Toast.makeText(this, "부모님만 스탬프 선택이 가능합니다.", Toast.LENGTH_SHORT).show();
			}
			break;*/
		}
	}

	// 네.아니오.선택다이얼로그
	void alertDialog(String string_title, int int_code) {
		final String title = string_title;
		final int code = int_code;
		AlertDialog.Builder builder = new AlertDialog.Builder(
				NoticeDetailActivity.this);
		AlertDialog alert;
		builder.setMessage(title)
				.setCancelable(false)
				.setPositiveButton("네", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						startNetwork(code);
					}
				})
				.setNegativeButton("아니오",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								dialog.cancel();
							}
						});
		alert = builder.create();
		alert.show();
	}

	public void noReadThread() {
		String msg = "";
		try {
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_NOTICE_DETAIL_NOREAD + "&pk=" + noticeCode));
			if (jsonObject.getBoolean("success")) {
				onNetworkCallback(SUCCESS_NOREAD,
						jsonObject.getString("payload"));
			} else {
				onNetworkCallback(FAIL_NOREAD, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(CATCH_EXCEPTION, e.toString()+" where getError()");
		}
	}

	private final BroadcastReceiver mToastMessageReceiver = new BroadcastReceiver() {
		public void onReceive(Context context, Intent intent) {
			LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.toast_layout, null);
			TextView toast_tv = (TextView)layout.findViewById(R.id.TOAST_LAYOUT_TV);
			Toast toast = new Toast(NoticeDetailActivity.this);
			toast.setView(layout);
			toast_tv.setText(intent.getStringExtra("PUSH_NAME")+" : "+intent.getStringExtra("PUSH_SUB"));
			toast.setDuration(Toast.LENGTH_LONG);
			toast.show();
		}
	};
}// CLASS_END
